package com.example.adminserivce.Controller;


import com.example.adminserivce.Service.CourseService;
import com.example.common.domain.Result;
import com.example.common.domain.pojo.Course;
import com.example.common.domain.pojo.Teacher;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RefreshScope // 实时刷新配置信息
@Slf4j  // 日志 log.info("登录日志测试：");
@RequiredArgsConstructor
@RestController
@RequestMapping("/admins/course")
@Api(value = "管理员端课程管理", description = "课程管理")
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 获取所有课程信息
     *
     * @return
     */
    @GetMapping("getAll")
    public Result<List<Course>> getAllResources() {
        return Result.success(courseService.getListCourse());
    }

    /**
     * 根据课程id获取老师信息，返回List
     *
     * @return
     */
    @GetMapping("getTeacherInfo")
    public Result<List<Teacher>> getToTeacher(@PathVariable String courseId) {
        return Result.success(courseService.getToTeacher(courseId));
    }

    /**
     * 根据老师id获取课程信息，返回List
     *
     * @return
     */
    @GetMapping("getTeacherIdToCourseInfo")
    public Result<List<Course>> getTeacherIdToCourseInfo(@PathVariable String teacherId) {
        return Result.success(courseService.getTeacherIdToCourseInfo(teacherId));
    }


}
